{extend name="common/__admin"}

{block name="body"}
<blockquote class="layui-elem-quote layui-text">添加管理员，欢迎使用后台管理系统</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加管理员</legend>
</fieldset>

<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <select name="group_id">
                <option value="">选择角色</option>
                {volist name="groupList" id="vo"}
                <option value="{$vo.id}">{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="username" placeholder="用户名" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input" name="password" placeholder="不填则为123456" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="real_name" placeholder="昵称" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" value="1" lay-skin="switch" lay-text="正常|禁用" checked lay-filter="status">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submit">添加</button>
        </div>
    </div>
</form>
{/block}

{block name="js"}
<script>
    layui.use(['form'], function () {
        let $ = layui.jquery;

        // 提交
        layui.form.on("submit(submit)", function (obj) {
            if (isClick) {
                isClick = false;
                if (!obj.field.is_show) {
                    obj.field['is_show'] = 2
                }
                request($, "{:url('admin.Admin/addAdmin')}", obj.field, function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, function () {
                            location.reload();
                        });
                    } else {
                        isClick = true;
                        layer.msg(res.msg);
                    }
                });
            } else {
                layer.msg("不允许重复提交");
            }
            return false;
        });
    });
</script>
{/block}